package com.lemon.smartsafetynew.ui.adapter.me;

import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.ApplicationInfo;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.me.MeCompanyVo;

import java.util.List;

import butterknife.Bind;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2017/8/30.
 */

public class MeCompanyListAdapter extends LemonRcvAdapter<MeCompanyVo> {


    private RecyclerTClickListener<MeCompanyVo> mListener;
    private Boolean isShow;

    public MeCompanyListAdapter(@Nullable List<MeCompanyVo> data, RecyclerTClickListener<MeCompanyVo> mListener, Boolean isShow) {
        super(data);
        this.mListener = mListener;
        this.isShow = isShow;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new Item();
    }

    private class Item implements AdapterItem<MeCompanyVo> {

        private MeCompanyVo mData;
        private int mPosition;
        private TextView tvPlanCount;
        private ImageView ivToRight;
        private TextView companyNameTv;
        private LinearLayout mLinearLayout;

        @Override
        public int getLayoutResId() {
            return R.layout.item_company;
        }

        @Override
        public void bindViews(View root) {
            companyNameTv = (TextView) root.findViewById(R.id.company_name_tv);
            mLinearLayout = (LinearLayout) root.findViewById(R.id.layout);
            tvPlanCount = (TextView) root.findViewById(R.id.tv_plan_count);
            ivToRight = (ImageView) root.findViewById(R.id.iv_to_right);
        }

        @Override
        public void setViews() {
            mLinearLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(mData, mPosition);
                }
            });
        }

        @Override
        public void handleData(MeCompanyVo meCompanyVo, int position) {

            mData = meCompanyVo;
            mPosition = position;
            if (isShow){
                tvPlanCount.setVisibility(View.VISIBLE);
                ivToRight.setVisibility(View.VISIBLE);
                if(null != meCompanyVo.getContingency_count() ){
                    int number = meCompanyVo.getContingency_count();
                    tvPlanCount.setText(number+"个预案");
                    if(number == 0){
                        tvPlanCount.setTextColor(Color.parseColor("#EA654F"));
                    }else{
                        tvPlanCount.setTextColor(Color.parseColor("#D3D2D0"));
                    }

                }
            }else{
                tvPlanCount.setVisibility(View.GONE);
                ivToRight.setVisibility(View.GONE);
            }
            companyNameTv.setText(meCompanyVo.getCompany_name() + "");

        }
    }
}
